<?php

namespace App\Http\Controllers;

use Laravel\Lumen\Routing\Controller as BaseController;

class Controller extends BaseController
{
    protected $dbTongji;
    protected $dbAdmin;
    protected $dbVideo;
    protected $dbMeet;
    protected $dbFront;
    protected $dbTrend;

    public function __construct()
    {
    }

    //接口返回格式
    public function toJson($code=0,$msg='',$data=[],$total=0)
    {
        $json = [
            'code'=>$code,
            'msg'=>$msg?$msg:'成功',
        ];
        if ($data) {
            $json['data'] = $data;
            $json['total'] = $total;
        }
        return json_encode($json,JSON_UNESCAPED_UNICODE);
    }

    /**
     * JSON转化为数组
     */
    public function jsonToArr($str) {
        if (is_string($str)) {
            $str = json_decode($str);
        }
        $arr = array();
        foreach($str as $k=>$v) {
            if(is_object($v) || is_array($v)) {
                $arr[$k] = $this->jsonToArr($v);
            } else {
                $arr[$k] = $v;
            }
        }
        return $arr;
    }
}